﻿using System;
using System.Globalization;
using System.Xml.Serialization;

namespace CarFileManager.Models
{
    public class XmlCar : ICar
    {
        private const string XML_DATE_TIME_FORMAT = "dd.MM.yyyy";

        [XmlElement("Date")]
        public string DateString
        {
            get
            {
                return Date.ToString(XML_DATE_TIME_FORMAT, CultureInfo.InvariantCulture);
            }
            set
            {
                DateTime date;
                if (DateTime.TryParseExact(value, XML_DATE_TIME_FORMAT, CultureInfo.InvariantCulture, DateTimeStyles.None, out date))
                {
                    Date = date;
                }
            }
        }

        #region ICar implementation

        [XmlIgnore]
        public DateTime Date { get; set; }

        [XmlElement("BrandName")]
        public string BrandName { get; set; }

        [XmlElement("Price")]
        public int Price { get; set; }

        #endregion
    }
}